home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-09 | 3.0 KB | 130 lines | [TEXT/CWIE] |
- // Copyright (C) 1999 Eric Roccasecca. All rights reserved.
-
- #include "init.h"
- #include "X_Ray.h"
-
- #define kTransparencyOpaque 0x0000
- #define kTransparencyClear 0xFFFF
-
- OSErr gErr = noErr;
- flt_GlobalCommRec gCommRec;
- GetNextEventFilterUPP gOldjGNEFilter = nil,
- gGNEFilterUPP = nil;
- SelectorFunctionUPP gGestaltUPP;
- RgnHandle gCheckRgn = nil;
-
-
- void main (void)
- {
- Handle theCode;
- THz savedZone;
-
- savedZone = GetZone(); // make sure we are in a safe memory zone
- SetZone (SystemZone());
-
- gCommRec.daemonPSN.lowLongOfPSN = 0;
- gCommRec.daemonPSN.highLongOfPSN = 0;
- gCommRec.daemonWindow = nil;
- gCommRec.daemonZone = 0;
- gCommRec.daemonQDGlobals = nil;
- gCommRec.daemonWindow = nil;
-
- if (InstalStuff())
- {
- // keep us around after INIT file is closed
- theCode = Get1Resource ('INIT', 128);
- DetachResource (theCode);
-
- gCheckRgn = NewRgn();
- }
-
- SetZone (savedZone); // restore memory zone
- }
-
-
- // passes back to caller a pointer to the global communication rec
- pascal OSErr flt_Gestalt (OSType selector, long *response)
- {
- #pragma unused (selector, response)
- *response = (long)&gCommRec;
- return noErr;
- }
-
-
- OSErr IsDaemonRunning (void)
- {
- ProcessInfoRec info;
-
- info.processInfoLength = sizeof(ProcessInfoRec);
- info.processName = nil;
- info.processAppSpec = nil;
- return GetProcessInformation (&gCommRec.daemonPSN, &info);
- }
-
-
- Boolean InstalStuff (void)
- {
- gGestaltUPP = NewSelectorFunctionProc (flt_Gestalt);
- gErr = NewGestalt (kfltGestalt, gGestaltUPP);
- if (gErr)
- return false;
-
- // Install GNE filter routine
- gOldjGNEFilter = LMGetGNEFilter();
- gGNEFilterUPP = NewGetNextEventFilterProc (flt_GNEFilter);
- LMSetGNEFilter ((GNEFilterUPP)gGNEFilterUPP);
-
- return true;
- }
-
-
- // handles all events regarding the floating windows
- pascal void flt_GNEFilter (EventRecord *theEvent, Boolean *result)
- {
- WindowPtr foundWin;
- short foundWinPart;
-
- if (gOldjGNEFilter)
- CallGetNextEventFilterProc (gOldjGNEFilter, theEvent, result);
-
- if (gCommRec.daemonWindow && (IsDaemonRunning() == noErr))
- {
- // check for mouse related happenings
- UnionRgn (((WindowPeek)gCommRec.daemonWindow)->strucRgn, ((WindowPeek)gCommRec.daemonWindow)->contRgn, gCheckRgn);
- if (PtInRgn (theEvent->where, gCheckRgn))
- {
- RgnHandle checkRgn = nil;
-
- foundWinPart = FindServiceWindow (theEvent->where, &foundWin);
- if (foundWin)
- {
- switch (theEvent->what)
- {
- case mouseDown:
- if (foundWin == gCommRec.daemonWindow)
- {
- switch (foundWinPart) {
- case inDrag:
- DragWindow (foundWin, theEvent->where, &(*LMGetGrayRgn())->rgnBBox);
- break;
- case inGoAway:
- gCommRec.daemonCloseWindow = TrackGoAway (foundWin, theEvent->where);
- if (gCommRec.daemonCloseWindow)
- gErr = WakeUpProcess (&gCommRec.daemonPSN);
- break;
- default:
- break;
- }
-
- // event has been handled, don't pass it on
- theEvent->what = nullEvent;
- }
- break;
- default:
- break;
- }
- }
- }
- }
- }
-